package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.BaseCapacityRule;
import com.sailfish.springbootdemo.pojo.db1.TechCapacityRule;
import com.sailfish.springbootdemo.service.db1.BaseCapacityRuleService;
import com.sailfish.springbootdemo.service.db1.TechCapacityRuleService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/techCapacityRule")
public class TechCapacityRuleController {

    @Autowired
    private TechCapacityRuleService techCapacityRuleService;

    @PostMapping("/getAllTechCapacityRule")
    public Result getAllTechCapacityRule(String searchValue, Integer lineTechBigTypeId, Integer lineTechSmallTypeId) {
        try {
            return ResultUtil.success(techCapacityRuleService.getAllTechCapacityRule(searchValue, lineTechBigTypeId, lineTechSmallTypeId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/updateTechCapacityRule")
    public Result updateTechCapacityRule(TechCapacityRule techCapacityRule) {
        return techCapacityRuleService.updateTechCapacityRule(techCapacityRule);
    }

    @PostMapping("/deleteTechCapacityRule")
    public Result deleteTechCapacityRule(Integer techCapacityRuleId) {
        return techCapacityRuleService.deleteTechCapacityRule(techCapacityRuleId);
    }

    @PostMapping("/addOrUpdateTechCapacityRule")
    public Result addOrUpdateTechCapacityRule(String mode, TechCapacityRule techCapacityRule) {
        return techCapacityRuleService.addOrUpdateTechCapacityRule(mode, techCapacityRule);
    }

    @PostMapping("/changeActualEqualDeclare")
    public Result changeActualEqualDeclare(Integer techCapacityRuleId) {
        return techCapacityRuleService.changeActualEqualDeclare(techCapacityRuleId);
    }
}
